const {
  loginCheck
} = require('../controller/user')
const { SuccessModel, ErrorModel } = require('../model/resModel')

const handleUserRouter = (req, res) => {
  const {method, url} = req
  const path = url.split('?')[0]

  // 登录
  if (method === 'POST' && path === '/api/user/login') {
    const { username, password } = req.body
    const result = loginCheck(username, password)
    return result.then(res => {
      if (res.length !== 0) {
        return new SuccessModel('登陆成功')
      }
      return new ErrorModel('登陆失败，请检查账户或者密码')
    })
  }
}

module.exports = handleUserRouter